package cn.zn.modules.pz.his.service.impl;

import cn.zn.modules.pz.his.entity.PzExpense;
import cn.zn.modules.pz.his.entity.QPzExpense;
import cn.zn.modules.pz.his.repository.PzExpenseRepository;
import cn.zn.modules.pz.his.service.PzExpenseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
@Slf4j
public class PzExpenseServiceImpl implements PzExpenseService {

    @Autowired
    private PzExpenseRepository pzExpenseRepository;

    @Override
    public List<PzExpense> findByMainIds(Integer ap, List<String> mainIds) {
        QPzExpense qPzExpense = QPzExpense.pzExpense;
        return (List<PzExpense>) pzExpenseRepository.findAll(qPzExpense.ap.eq(ap).and(qPzExpense.mainId.in(mainIds)));
    }

    @Override
    public PzExpense findByMainId(Integer ap, String mainId) {
        QPzExpense qPzExpense = QPzExpense.pzExpense;
        Optional<PzExpense> one = pzExpenseRepository.findOne(qPzExpense.ap.eq(ap).and(qPzExpense.mainId.in(mainId)));
        if (one.isPresent()) {
            return one.get();
        }
        return null;
    }
}
